package com.liyu.config;

import com.rabbitmq.client.BuiltinExchangeType;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author 李誉
 * @date 2022-07-04 21:30
 * @description 延迟队列
 */
@Component
public class DelayedComment {

    public static final String DELAYED_EXCHANGE = "delayed.exchange.hello";

    public static final String DELAYED_QUEUE = "delayed.queue.hello";

    public static final String DELAYED_ROUTING_KEY = "delayed.rk.hello";

    /**
     * 交换机
     */
    @Bean("delayedExchange")
    public Exchange delayedExchange() {
        return new ExchangeBuilder(DELAYED_EXCHANGE, BuiltinExchangeType.DIRECT.getType()).delayed().build();
    }

    /**
     * 队列
     */
    @Bean("delayedQueue")
    public Queue delayedQueue() {
        return QueueBuilder.durable(DELAYED_QUEUE).build();
    }

    @Bean("delayedBinding")
    public Binding delayedBinding(Queue delayedQueue, Exchange delayedExchange) {
        return BindingBuilder.bind(delayedQueue).to(delayedExchange).with(DELAYED_ROUTING_KEY).noargs();
    }

}
